package com.ruoyi.pg.pensionProject.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.pg.pensionProject.domain.PgProject;
import com.ruoyi.pg.pensionProject.service.IPgRoleProjectService;
import com.ruoyi.pg.pensionProject.vo.PgProjectVo;
import com.ruoyi.pg.pensionProject.mapper.PgProjectMapper;
import com.ruoyi.pg.pensionProject.service.IPgProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 养老项目Service业务层处理
 *
 * @author Ming
 * @date 2025-09-03
 */
@Service
@Transactional
public class PgProjectServiceImpl extends ServiceImpl<PgProjectMapper, PgProject> implements IPgProjectService {

    @Autowired
    private IPgRoleProjectService roleProjectService;

    @Override
    @DataScope(deptAlias = "d", userAlias = "u")
    @Transactional(readOnly = true)
    public TableDataInfo<PgProjectVo> queryList(PgProjectVo entity) {
        return PageUtils.buildDataInfo(this.baseMapper.queryList(PageUtils.buildPage(), entity));
    }

    @Override
    @Transactional(readOnly = true)
    public List<PgProjectVo> queryAll(PgProjectVo entity) {
        if (ObjectUtil.isNotEmpty(entity.getRoleId()) && entity.getRoleId().size() > 0) {
            List<Long> projectIds = roleProjectService.getProjectIds(entity.getRoleId());
            if (projectIds.size() > 0) entity.setIds(projectIds);
        }
        return this.baseMapper.queryList(entity);
    }

    @Override
    @Transactional(readOnly = true)
    public PgProjectVo queryById(Long id) {
        return this.baseMapper.queryById(id);
    }
}
